package eTaxi;

import java.io.*;
import java.net.*;

public class Taxi {

	static InetAddress taxiAddr;

	static String taxiIp;

	static int taxiport = 15555;

	static TaxiProfile tp;

	static BufferedReader reader;

	static String taxiname;

	static Lock lock = new Lock();

	static Lock lock2 = new Lock();

	/*
	 *  La classe Taxi crea il TaxiProfile , inizializza i thread e li manda in
     *  esecuzione
	 */
	public static void main(String[] args) {

		System.out.println("Inserire il nome del Taxi");

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		try {
			taxiname = in.readLine();
		} catch (IOException ioe) {
			System.out.println(ioe);
			return;
		}

		
		int taxiport = 15555;

		try {
			taxiAddr = InetAddress.getLocalHost();
			taxiIp = taxiAddr.getHostAddress();

		}

		catch (UnknownHostException uhe) {
			System.out.println("Errore: " + uhe);
			return;
		}

		TaxiProfile tp = new TaxiProfile(taxiname, taxiIp, taxiport, true);

		UserHandler userhandler = new UserHandler(tp, lock, lock2);
		BankHandler bankhandler = new BankHandler(tp, lock, lock2);

		userhandler.init(bankhandler);
		bankhandler.init(userhandler);

		userhandler.start();
		bankhandler.start();

		

	}// fine main
}// fine Taxi
